﻿using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MJB.UI.ContentEditor.Document;
using MJB.UI.ContentEditor.Windows;

namespace MJB.UI.ContentEditor.UserControls
{
    /// <summary>
    /// Contains the events of the tab item control object.
    /// </summary>
    public partial class TabItemControl : UserControl
    {
        #region Constructor

        /// <summary>
        /// Creates the tab item control.
        /// </summary>
        public TabItemControl()
        {
            InitializeComponent();
        }

        #endregion
        #region Event Handlers

        /// <summary>
        /// Called when the new section button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void OnNewSectionButtonClicked(object sender, RoutedEventArgs args)
        {
            Button button = (Button)sender;
            IDocumentReader documentReader = (IDocumentReader)button.DataContext;

            ISection newSection = documentReader.CreateNewSection();
            newSection.SectionTitle = "Untitled";
            newSection.SectionText = String.Empty;
            documentReader.Sections.Insert(0, newSection);

        }

        /// <summary>
        /// Called when the generate button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void OnGenerateButtonClicked(object sender, EventArgs args)
        {
            Button button = (Button)sender;

            IDocumentReader reader = (IDocumentReader)button.DataContext;
            KeyWordGeneratorWindow generatorWindow = new KeyWordGeneratorWindow();
            generatorWindow.Owner = Application.Current.MainWindow;
            generatorWindow.SetDocumentReader(reader);
            generatorWindow.ShowDialog();

            string keyWords = generatorWindow.GetSelectedKeyWords();
            if(keyWords != null)
                reader.Keywords = keyWords;

        }

        #endregion

    }

}
